import axios from 'axios'

const instance = axios.create({
  baseURL: window.NEBULA_API_URL,
  timeout: 10000,
  headers: {},
})

export const portalInstance = axios.create({
  baseURL: window.PORTAL_API_URL,
  // baseURL: 'http://localhost:9877/',
  timeout: 10000,
  headers: { Authorization: localStorage.getItem('token') },
})

export async function nebulaExec(gql: string) {
  try {
    const response = await instance.get('/', {
      params: {
        q: gql,
      },
    })
    if (response.data.err) {
      throw response.data.err
    }
    return response.data
  } catch (error) {
    console.error(error)
    throw error
  }
}
